<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止事件冒泡</title>
    <style>
        .father {
            overflow: hidden;
            width: 500px;
            height: 500px;
            background-color: skyblue;
            margin: 100px auto;
            text-align: center;
        }

        .son {
            width: 300px;
            height: 300px;
            background-color: yellow;
            margin: 80px auto;
            text-align: center;
            line-height: 300px;
        }
    </style>
</head>

<body>
<div class="father">
    父盒子
    <div class="son">子盒子</div>
</div>
<script>
    // 事件流
    const father = document.querySelector('.father')
    const son = document.querySelector('.son')
    // 点击父盒子
    father.addEventListener('click', function () {
        alert('我是爸爸')
    })
    // 需求: 点击子盒子, 只弹出我是儿子, 不要弹出我是爸爸
    son.addEventListener('click', function (e) {
        // 阻止冒泡需要事件对象
        // 阻止冒泡 英[ˌprɒpəˈɡeɪʃ(ə)n]
        e.stopPropagation()
        // 对象.stopPropagation()
        alert('我是儿子')
    })
</script>
</body>

</html>